package com.mmm.station.security.method;

import com.mmm.station.security.utils.ClassUtils;
import com.mmm.station.security.utils.ContextHolderUtils;
import com.mmm.station.security.utils.PropertiesUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by mmm on 2016/12/5.
 */
public class ExclusionUrls {
    private static Logger logger = LogManager.getLogger(ExclusionUrls.class);
    public static List<String> fulUrls = null;
    public static List<String> beginUrls = null;
    public static List<String> endUrls = null;
    public static boolean ex = false;

    static {

        String urls = PropertiesUtils.getProperty(ClassUtils.getClassPath() + "/application.properties", "mmm.common.exclusionUrls");
        if (urls != null && ex == false) {
            fulUrls = new ArrayList<>();
            fulUrls.add("/favicon.ico");
            beginUrls = new ArrayList<>();
            endUrls = new ArrayList<>();
            ex = true;
//            logger.info("配置");
            String[] urlss = urls.split(",");
            for (String url : urlss) {
                if (url.endsWith("/**")) {
                    beginUrls.add(url.replace("/**", ""));
                } else if (url.startsWith("/**.")) {
                    endUrls.add(url.replace("/**",""));
                } else {
                    fulUrls.add(url);
                }
            }
        }
    }

//
//    public static void setUrls(){
//        String urls = PropertiesUtils.getProperty(ClassUtils.getClassPath() + "/application.properties", "benyun.common.exclusionUrls");
//        if (urls != null) {
//            fulUrls = new ArrayList<>();
//            beginUrls = new ArrayList<>();
//            ex = true;
//            logger.info("配置文件执行了");
//            String[] urlss = urls.split(",");
//            for (String url : urlss) {
//                if (url.contains("/**")) {
//                    beginUrls.add(url.replace("/**", ""));
//                } else if (url.contains("**.")) {
//                    endUrls.add(url);
//                } else {
//                    fulUrls.add(url);
//                }
//            }
//        }
//    }

}
